<!-- 
	修改密码
 -->
<template>
	<view class="changepsd">
		<cu-custom :isBack="true" bgColor="bg-fa">
			<block slot="content">修改密码</block>
		</cu-custom>
		<view class="form-box">
			<view class="input-label">
				<view class="label">
					原密码
				</view>
				<view>
					<l-input icon-font="32" incon-color="#E54D42" input-type="password"
					placeholder-text="请输入原密码"
					 :max-lenght="16" val-name="password" @getVal="getVal"></l-input>
				</view>
			</view>
			
			<view class="input-label">
				<view class="label">
					新密码
				</view>
				<view>
					<l-input icon-font="32" incon-color="#E54D42" input-type="password"
					placeholder-text="请输入新密码"
					 :max-lenght="16" val-name="newpsd" @getVal="getVal"></l-input>
				</view>
			</view>
			
			<view class="input-label">
				<view class="label">
					确认新密码
				</view>
				<view>
					<l-input icon-font="32" incon-color="#E54D42" input-type="password"
					placeholder-text="请再次输入新密码"
					 :max-lenght="16" val-name="repsd" @getVal="getVal"></l-input>
				</view>
			</view>
			
		</view>
		
		<view class="submit-btn">
			<u-button @tap="submitInfo" shape="circle" :ripple="true" :custom-style="{'background':'#FA436A','borderColor':'#FA436A','color':'#fff'}">确认修改</u-button>
		</view>
		
		
		
	</view>
</template>

<script>
	import lInput from "@/components/input/lInput.vue"
	export default {
		name:"changepsd",
		data(){
			return {
				password:"",
				newpsd:"",
				repsd:""
			}
		},
		components:{
			lInput
		},
		methods:{
			getVal(val,name){
				this[name] = val
			},
			submitInfo(){
				let t = setTimeout(()=>{
					clearTimeout(t)
					let has = this.vaildPasswold()
					if(has){
						
					}
				},100)
				
			},
			vaildPasswold(){
				let reg = /^[a-zA-Z0-9]{6,16}$/
				let psd = this.password.trim()
				let newpsd = this.newpsd.trim()
				let repsd = this.repsd.trim()
				if(psd.length.length == 0 || newpsd.length.length == 0 || repsd.length == 0){
					uni.showToast({
						icon:"none",
						title:"请输入密码",
						duration:1500
					})
					return false
				}
				if(psd.length<6 || psd.length>16){
					uni.showToast({
						icon:"none",
						title:"原密码长度必须为6-16位",
						duration:2000
					})
					return false
				}
				if(!reg.test(psd)){
					uni.showToast({
						icon:"none",
						title:"原密码不是6-16位英文和数字组成",
						duration:2000
					})
					return false
				}
				if(newpsd.length<6 || newpsd.length>16){
					uni.showToast({
						icon:"none",
						title:"原密码长度必须为6-16位",
						duration:2000
					})
					return false
				}
				if(!reg.test(newpsd)){
					uni.showToast({
						icon:"none",
						title:"原密码不是6-16位英文和数字组成",
						duration:2000
					})
					return false
				}
				if(newpsd != repsd){
					uni.showToast({
						icon:"none",
						title:"两次输入密码不一致",
						duration:2000
					})
					return false
				}
				return true
			}
		},
		onLoad() {
			
		}
	}
</script>

<style scoped lang="scss">
	.changepsd{
		.form-box{
			width: calc(100% - 40rpx);
			margin-left: 20rpx;
			background: #FFFFFF;
			margin-top: 50rpx;
			padding: 0 20rpx;
			border-radius: 20rpx;
		}
		.input-label{
			padding-bottom: 10rpx;
			border-bottom: 1px solid #f1f1f1;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding-top: 10rpx;
			.label{
				width: 160rpx;
				min-width: 160rpx;
				max-width: 160rpx;
				color: #666666;
				font-size: 28rpx;
			}
			.input-code-l{
				flex-grow: 1;
			}
			.input-code-r{
				width: 240rpx;
				padding: 0 10rpx;
				border-radius: 6rpx 6rpx;
				border: 2rpx solid #FA436A;
				background: #FA436A;
				flex-grow: 0;
				height: 70rpx;
				text-align: center;
				line-height: 70rpx;
				.code{
					font-size: 20rpx;
					color: #FFFFFF;
				}
			}
		}
		.submit-btn{
			width: 90%;
			margin-left: 5%;
			margin-top: 80rpx;
		}
	}
</style>
